import Vue from 'vue'
import VueRouter from 'vue-router'
import Film from '@/views/Film'
import Cinema from '@/views/Cinema'
import Center from '@/views/Center'
import Comingsoon from '@/views/Film/Comingsoon'
import Nowplaying from '@/views/Film/Nowplaying'
import Detail from '@/views/Detail'
import Login from '@/views/Login'

Vue.use(VueRouter)

const auth = {
	isLogin(){
		return false;
	}
}

const routes = [{
		path: '/film',
		name: 'Film',
		component: Film,
		children: [{
				path: "nowplaying",
				component: Nowplaying
			},
			{
				path: 'comingsoon',
				component: Comingsoon
			},
			{
				path: "",
				component: Nowplaying
			}
		]
	},
	{
		path: '/detail/:id', // 动态路由
		name: "detail",
		component: Detail
	},
	{
		path: '/cinema',
		name: 'Cinema',
		component: Cinema
	},
	{
		path: '/center',
		name: 'Center',
		component: Center
	}, 
	{
		path: '/login',
		name: "login",
		component: Login
	},	
	{
		path: "",
		redirect: '/film'
	}
]

const router = new VueRouter({
	mode: 'history',
	routes
})

//全局守卫
router.beforeEach((to, from, next) => {
	
	if(to.path === '/center'){
		console.log("盘查")
		if(auth.isLogin()){
			next();
		}else{
			next('/login');
		}
	}else{
		next();
	}
})

export default router
